//
//  ViewController.m
//  王宇先_07_登录界面_navigation
//
//  Created by wyx on 16/3/17.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "ViewController.h"
#import "ViewOfLogIn.h"
#import "RootNavigationControllerViewController.h"
#import "ThirdViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor lightGrayColor];
    [self configForNavigationItem];
    UITextField *name = [[UITextField alloc] initWithFrame:CGRectMake(40, 100, self.view.frame.size.width - 80, 40)];
    name.placeholder = @"请输入用户名";
    name.borderStyle = 3;
    [self.view addSubview:name];
    [name release];
    UITextField *key = [[UITextField alloc] initWithFrame:CGRectMake(40, 160, self.view.frame.size.width - 80, 40)];
    key.placeholder = @"请输入密码";
    key.borderStyle = 3;
    [self.view addSubview:key];
    [key release];
    UIButton *login = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 2 - 20, 280, 40, 40)];
    [login setTitle:@"登录" forState:UIControlStateNormal];
    [login addTarget:self action:@selector(handleOfLogin:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:login];
    [login release];
}
- (void)configForNavigationItem{
    
    //中间title
    self.navigationItem.title = @"登录";
    //右边(rightBarButtonItem)
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(handleAdd:)]autorelease];
    
}
- (void)handleAdd:(UIBarButtonItem *)button {
    /** 核心 在模态推出界面后加 navigation */
    ViewOfLogIn *second = [[ViewOfLogIn alloc] init];
    RootNavigationControllerViewController *logVc = [[RootNavigationControllerViewController alloc] initWithRootViewController:second];
    [self presentViewController:logVc animated:YES completion:^{
    }];
    [second release];
    [logVc release];
}
-(void) handleOfLogin:(UIButton *)login {
    ThirdViewController *third = [[ThirdViewController alloc] init];
    [self.navigationController pushViewController:third animated:NO];
    [third release];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
